/* Exercise 5.28
   ejer5_28.c */
#include <stdio.h>

int reverseNumber( int number );

/* function main begins program execution */
int main( void )
{
    int number;

    printf( "Enter a number: " );
    scanf( "%d", &number );

    printf( "The reversed number is: %d\n", reverseNumber( number ));

	return 0; /* indicate that program ended successfully */
} /* end function main */

/* This function returns the number with digit reversed */
int reverseNumber( int number )
{
    int reversed = 0;
    int digit;

    while ( number != 0 )
    {
        digit = number % 10;
        reversed = 10 * reversed + digit;
        number /= 10;
    }

    return reversed;
} /* end function reverseNumber */
